const resultEnum = require('../utils/resultEnum').ResultEnum;
const Mock = new(require('../utils/mock')).Mocks();

/* 查询地址信息 */
function selectTemplateInfo(ctx, next) {
  try {
    const params = {
      ...ctx.query
    };
    console.log(params);
    /* 模拟查询数据库，处理后返回 */
    /* 返回对象 */

    ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getTemplateList())
  } catch (error) {
    ctx.error(resultEnum.GET_ERROR.code, resultEnum.GET_ERROR.msg)
  }
}

/* 查询地址信息通过id */
function selectTemplateInfoById(ctx, next) {
  const params = {
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getTemplateById())
}

/* 新增地址信息 */
function insertTemplate(ctx, next) {
  const params = {
    ...ctx.request.body
  };
  console.log(params);
  ctx.success(resultEnum.SAVE_SUCCESS.code, resultEnum.SAVE_SUCCESS.msg)
}

/* 更新地址信息 */
function updataTemplate(ctx, next) {
  const params = {
    ...ctx.request.body,
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.UPDATE_SUCCESS.code, resultEnum.UPDATE_SUCCESS.msg)
}

/* 删除地址信息 */
function deleteTemplate(ctx, next) {
  const params = {
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.DELETE_SUCCESS.code, resultEnum.DELETE_SUCCESS.msg)
}

module.exports = {
  selectTemplateInfo,
  selectTemplateInfoById,
  insertTemplate,
  updataTemplate,
  deleteTemplate
}